package com.lxw.study.creational.factorymethod.case2;

import java.sql.Connection;
import java.sql.SQLException;

public class FactoryMethodExample {
    public static void main(String[] args) throws SQLException {
        // 使用MySQL工厂创建MySQL数据库连接
        DatabaseConnectionFactory mysqlFactory = new MySqlConnectionFactory("jdbc:mysql://localhost:3306/mydb", "user", "password");
        DatabaseConnection mysqlConnection = mysqlFactory.createConnection();
        Connection mysqlConn = mysqlConnection.connect();
        System.out.println("Connected to MySQL database");

        // 使用Oracle工厂创建Oracle数据库连接
        DatabaseConnectionFactory oracleFactory = new OracleConnectionFactory("jdbc:oracle:thin:@localhost:1521:orcl", "user", "password");
        DatabaseConnection oracleConnection = oracleFactory.createConnection();
        Connection oracleConn = oracleConnection.connect();
        System.out.println("Connected to Oracle database");
    }
}
